if common_modifiers == nil then
	common_modifiers = {}
end
--[[
1.每个单位出生需要重新给予modifier
2.每次升级需要重新给予modifier
3.技能出现时需要modifier
]]
function common_modifiers:RegisterCommonModifier(Modifier,IsToFriendly) --注册
	local ability = Modifier:GetAbility()
	function Modifier:Init()
		self.IsToFriendly = IsToFriendly
		ListenToGameEvent("npc_spawned", Dynamic_Wrap(Modifier, "ApplyGlobalModifier"), self)
	end
	function Modifier:ApplyGlobalModifier(event)
		local spawned = EntIndexToHScript(event.entindex)
		print("Modifier:ApplyGlobalModifier")
		if spawned ==nil then return end
		spawned:SetContextThink(DoUniqueString("CheckingPlayerID"), 
			function()
				if spawned._playerID == nil then 
					return
				end
				print("Valid Modifier:ApplyGlobalModifier:",spawned._playerID)
				local player = PlayerResource:GetPlayer(spawned._playerID)
				if player == Modifier:GetAbility():GetCaster():GetPlayerOwner() then
					print("apply_modifier",self:GetName())
					local modifier = spawned:AddNewModifier(spawned, Modifier:GetAbility(), self:GetName(), nil)
					modifier:SetStackCount(ability:GetLevel())
				end
			end, 0)
		
	end
	function Modifier:GivePlayerUnitModifier(player,modifier_level)
		if player.unit_spawner == nil then return end
		for i =  1,#player.unit_spawner do
			if IsValidEntity(player.unit_spawner[i]) then
				local modifier = player.unit_spawner[i]:AddNewModifier(player.unit_spawner[i],  Modifier:GetAbility(), self:GetName(),{})
				modifier:SetStackCount(modifier_level)
			else
				table.remove(player.unit_spawner,i)
			end
		end
	end
	function ability:OnUpgrade()
		if not ability:IsItem() then
			Modifier:GivePlayerUnitModifier(ability:GetCaster():GetPlayerOwner(),Modifier.RegisterModifierName,ability:GetLevel())
			Modifier:SetStackCount(ability:GetLevel())
		end
	end
	Modifier:Init()
end
